//package com.zmn.plat.dubbo.impl.brand;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Objects;
//
//import javax.annotation.Resource;
//import javax.validation.constraints.NotEmpty;
//import javax.validation.constraints.NotNull;
//import javax.validation.constraints.Positive;
//import javax.validation.constraints.Size;
//
//import com.zmn.common.dto.VtDTO;
//import com.zmn.plat.utils.bean.BeanCopyUtils;
//import lombok.extern.log4j.Log4j2;
//import org.apache.dubbo.config.annotation.Service;
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.Cacheable;
//import com.zmn.common.constant.GlobalConsts;
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
//import com.zmn.plat.common.dto.brand.BaseBrandDRO;
//import com.zmn.plat.dubbo.interfaces.brand.BrandListRemoteService;
//import com.zmn.plat.dubbo.utils.DubboConsts;
//import com.zmn.plat.manager.interfaces.cache.BrandCache;
//import com.zmn.plat.model.entity.brand.BaseBrand;
//import com.zmn.plat.model.entity.brand.BaseBrandQuery;
//import com.zmn.plat.services.interfaces.brand.BaseBrandService;
//
///**
// * @author duanzuocai
// * @version v1.0
// * @类说明：品牌 dubbo 服务
// * @since 2018/10/31 14:18
// */
//@Log4j2
//@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
//@CacheConfig(cacheNames = "redis1h")
//public class BrandListRemoteServiceImpl implements BrandListRemoteService {
//
//    @Resource
//    BrandCache brandCache;
//    @Resource
//    BaseBrandService baseBrandService;
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:brands:all:'", cacheNames = "redis1h")
//    public ResponseDTO<List<BaseBrandDRO>> listAll() {
//        List<BaseBrand> brands = brandCache.listAll();
//        List<BaseBrandDRO> dros = new ArrayList<>();
//        brands.forEach(brand -> {
//            BaseBrandDRO dro = new BaseBrandDRO();
//            copy(brand, dro);
//            dros.add(dro);
//        });
//        return ResponseDTO.success(dros, GlobalConsts.SUCCESS_MSG);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<BaseBrandDRO>> listByBrandIdListAndStatus(List<Integer> brandIdList, Integer status) {
//        BaseBrandQuery query = new BaseBrandQuery();
//        query.setStatus(GlobalConsts.YES);
//        query.setBrandIdList(brandIdList);
//        List<BaseBrand> baseBrandList = baseBrandService.listByQuery(query);
//        List<BaseBrandDRO> baseBrandDROList = new ArrayList<>(baseBrandList.size());
//        baseBrandList.forEach(e -> {
//            BaseBrandDRO baseBrandDRO = new BaseBrandDRO();
//            BeanCopyUtils.copyProperties(e, baseBrandDRO);
//            baseBrandDROList.add(baseBrandDRO);
//        });
//
//        return ResponseDTO.success(baseBrandDROList);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listByServCategIdAndCategOneId(Integer servCategId, Integer categOneId) {
//        if (NumberUtil.isNullOrZero(servCategId) || NumberUtil.isNullOrZero(categOneId)) {
//            log.error("listByServCategIdAndCategOneId参数servCategId：{}，categOneId：{}", servCategId, categOneId);
//            return ResponseDTO.fail("服务分类ID和后台产品一级分类ID不能为空");
//        }
//
//        List<VtDTO> result = baseBrandService.listByServCategIdAndCategOneId(servCategId, categOneId);
//
//        return ResponseDTO.success(result);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:brand:pageno'+#p0+':size:'+#p1+':keyword:'+#p3", condition = "#brandId != null", cacheNames = "redis1h")
//    public ResponseDTO<List<BaseBrandDRO>> listByPage(Integer pageNum, Integer pageSize, String keyword) {
//        if (NumberUtil.isNullOrZero(pageNum) || NumberUtil.isNullOrZero(pageSize)) {
//            return ResponseDTO.fail("入参页码不能为空");
//        }
//
//        pageSize = pageSize > 500 ? 500 : pageSize;
//        BaseBrandQuery query = new BaseBrandQuery();
//        query.setPageSize(pageSize);
//        query.setPageIndex(pageNum);
//        query.setNameOrBrandId(keyword);
//        List<BaseBrand> brands = baseBrandService.listPageByQuery(query);
//        List<BaseBrandDRO> dros = new ArrayList<>(brands.size());
//        brands.forEach(brand -> {
//            BaseBrandDRO dro = new BaseBrandDRO();
//
//            copy(brand, dro);
//
//            dros.add(dro);
//        });
//
//        return ResponseDTO.success(dros, GlobalConsts.SUCCESS_MSG);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:brand:id'+#p0", condition = "#brandId != null", cacheNames = "redis1h")
//    public ResponseDTO<BaseBrandDRO> getByBrandId(Integer brandId) {
//        BaseBrand brand = brandCache.findByKey(brandId);
//        BaseBrandDRO dro = new BaseBrandDRO();
//
//        copy(brand, dro);
//
//        return ResponseDTO.success(dro, GlobalConsts.SUCCESS_MSG);
//    }
//
//    private void copy(BaseBrand brand, BaseBrandDRO dro) {
//        if (Objects.isNull(brand) || Objects.isNull(dro)) {
//            return;
//        }
//        dro.setBrandId(brand.getBrandId());
//        dro.setName(brand.getName());
//        dro.setEnname(brand.getEnname());
//        dro.setFirstLetter(brand.getFirstLetter());
//        dro.setSort(brand.getSort());
//        dro.setIcon(brand.getIcon());
//        dro.setType(brand.getType());
//        dro.setStatus(brand.getStatus());
//    }
//}
